<?php
/**
 * Presenter class definition
 *  
 * @author Sean Crystal <seancrystal@gmail.com>
 * @package MVP-PHP
 */        
require_once 'interfaces/iPresenter.php';
require_once 'interfaces/iView.php';
require_once 'interfaces/iSession.php';

/**
 * This class implements the presenter pattern, coordinating and communicating
 * between the view and the model
 * @package MVP-PHP
 * @subpackage Presenters
 */   
class Presenter extends RequestHandler implements iPresenter
{
	/**
 	 * Constructor
	 * @param iView $view
	 * @param Request|null $request
	 * @param iSession|null $session
	 */    	
	public function __construct(iView $view, Request $request = null, iSession $session = null)
	{
		$this->view = $view;
		
		$this->Setup();
		
		if ($request) {
			$this->SetupHandlers($request);
		}
		
		if ($session) {
			$this->session = $session;
		}
	}
	
	/**
 	 * Attach a presenter as a child to this presenter
	 * @param Presenter $presenter
	 * @return Presenter
	 */     	
	public function AttachSubPresenter(Presenter $presenter)
	{
		$this->subPresenters[] = $presenter;
		
		return $presenter;
	}
	
	/**
     * Perform any tasks necessary before requests can he handled
	 */ 	
	protected function Setup() {}
	
	/**
     * array of attached child presenters
	 * @var array
	 */  	
	protected $subPresenters;
	
	/**
 	 * attached view
	 * @var iView
	 */  	
	protected $view;
	
	/**
     * attached session
	 * @var iSession
	 */  	
	protected $session;
}



?>